From: Florian Müllner Date: Thu, 1 Sep 2011 17:33:31 +0000 (+0200) Subject: popup-menu: Allow updating combobox items with scroll wheel X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~7822 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=86aa4fe0a95f98d8eff03985bedf20f25d9cdfe1;p=gnome-shell.git popup-menu: Allow updating combobox items with scroll wheel Rather than opening the combobox menu, allow using the scroll wheel to cycle through the visible items. https://bugzilla.gnome.org/show_bug.cgi?id=657973 --- diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index c272de723..2551d687e 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -1507,6 +1507,10 @@ PopupComboMenu.prototype = { } this._getMenuItems()[position].actor.visible = visible; + }, + + getItemVisible: function(position) { + return this._getMenuItems()[position].actor.visible; } }; @@ -1533,6 +1537,8 @@ PopupComboBoxMenuItem.prototype = { if (params.style_class) this._menu.actor.add_style_class_name(params.style_class); + this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent)); + this._activeItemPos = -1; this._items = []; }, @@ -1551,6 +1557,33 @@ PopupComboBoxMenuItem.prototype = { return null; }, + _onScrollEvent: function(actor, event) { + if (this._activeItemPos == -1) + return; + + let position = this._activeItemPos; + let direction = event.get_scroll_direction(); + if (direction == Clutter.ScrollDirection.DOWN) { + while (position < this._items.length - 1) { + position++; + if (this._menu.getItemVisible(position)) + break; + } + } else if (direction == Clutter.ScrollDirection.UP) { + while (position > 0) { + position--; + if (this._menu.getItemVisible(position)) + break; + } + } + + if (position == this._activeItemPos) + return; + + this.setActiveItem(position); + this.emit('active-item-changed', position); + }, + activate: function(event) { let topMenu = this._getTopMenu(); if (!topMenu)